<template>
  <el-dialog
      :title="classData.organization_name + ' ' + classData.grade_name + ' ' + classData.name"
      :visible="visible"
      width="80%"
      :destroy-on-close="true"
      :lock-scroll="false"
      @update:visible="updateVisible">
    <el-form
        inline size="mini"
        :model="where"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
      <el-form-item>
        <el-input clearable v-model="where.name" placeholder="请输入学生姓名"/>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" icon="el-icon-search" class="ele-btn-icon" @click="reload">查询
        </el-button>
        <el-button size="mini" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        height="calc(100vh - 415px)">
      <template slot="avatar" slot-scope="{row}">
        <el-avatar shape="square" :size="25" :src="row.avatar"/>
      </template>
    </ele-pro-table>
  </el-dialog>
</template>

<script>

export default {
  props: {
    visible: Boolean,
    classData: Object
  },
  data() {
    return {
      columns: [
        {
          prop: 'id',
          label: 'ID',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,
          fixed: "left"
        },
        {
          label: '头像',
          showOverflowTooltip: true,
          width: 100,
          align: 'center',
          slot: 'avatar',
        },
        {
          prop: 'name',
          label: '姓名',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'id_card',
          label: '学号',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'school_name',
          label: '学校',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'grade_name',
          label: '年级',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'class_name',
          label: '班级',
          minWidth: 100,
          resizable: false,
          align: 'center',
        },
        {
          prop: 'create_time',
          label: '创建时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        }
      ],
      where: {}
    }
  },
  computed: {
    url: function () {
      console.log(this.classData)
      return '/student/index?class_id=' + this.classData.id + '&school_id=' + this.classData.organization + '&grade_id=' + this.classData.grade
    }
  },

  methods: {
    reload() {
      this.$refs.table.reload({where: this.where})
    },
    reset() {
      this.where = {}
      this.reload()
    },
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>